package com.sutuijingling.a;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.sutuijingling.bean.TopBean;
import com.sutuijingling.result.WorkStatus;
import com.sutuijingling.result.c;
import com.sutuijingling.result.w;
import com.sutuijingling.utils.a;
import com.sutuijingling.utils.b;
import org.apache.http.HttpStatus;

public class j extends i {
    private UiObject w = null;

    public j(TopBean topBean, UiDevice uiDevice) {
        super(uiDevice);
        this.searchParams = topBean.getSearchBean();
        this.accParams = topBean.getAcc();
        this.missionId = topBean.getTaskId();
    }

    private void W() throws UiObjectNotFoundException, c {
        if (!X()) {
            System.out.println("check is taoqianggou item page:false");
            com.sutuijingling.utils.c.f();
            if (!X()) {
                System.out.println("check is taoqianggou item page:false");
                throw new c(HttpStatus.SC_NOT_FOUND, "淘抢购宝贝页面进入失败！");
            }
        }
        System.out.println("check is taoqianggou item page:true");
        for (int i = 0; i < 2; i++) {
            simpleDragScroll(true);
            com.sutuijingling.utils.c.c();
        }
        com.sutuijingling.utils.c.a(this.device, (this.device.getDisplayWidth() * 3) / 4, this.device.getDisplayHeight() - 30);
        com.sutuijingling.utils.c.e();
    }

    private boolean X() throws UiObjectNotFoundException {
        System.out.println("check is taoqianggou item page......");
        String b = a.b("dumpsys activity | grep  -i  \"cmp=com.taobao.taobao/com.taobao.browser.BrowserActivity\"");
        return !org.apache.commons.lang.c.a(b) && this.searchParams.getId().longValue() > 0 && b.contains("" + this.searchParams.getId());
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void Y() throws com.android.uiautomator.core.UiObjectNotFoundException, com.sutuijingling.result.c {
        /*
        r9 = this;
        r1 = 1;
        r4 = 0;
        r2 = r9.missionId;
        r0 = 8000; // 0x1f40 float:1.121E-41 double:3.9525E-320;
        com.sutuijingling.result.w.a(r2, r0);
        com.sutuijingling.utils.c.c();
        r2 = 0;
        r3 = r4;
        r0 = r4;
    L_0x000f:
        r5 = r3 + 1;
        r6 = 30;
        if (r3 >= r6) goto L_0x00a5;
    L_0x0015:
        r2 = r9.ac();
        if (r2 != 0) goto L_0x0026;
    L_0x001b:
        r9.ad();
        r0 = "isNeedBreak become true ----";
        r2 = new java.lang.Object[r4];
        com.sutuijingling.utils.b.b(r0, r2);
        r0 = r1;
    L_0x0026:
        r2 = r9.ab();
        if (r2 == 0) goto L_0x0059;
    L_0x002c:
        r3 = r2.exists();
        if (r3 != r1) goto L_0x0059;
    L_0x0032:
        r3 = r2.getBounds();
        r6 = r3.bottom;
        r3 = r9.device;
        r3 = r3.getDisplayHeight();
        r7 = r9.aa();
        if (r7 == 0) goto L_0x0050;
    L_0x0044:
        r8 = r7.exists();
        if (r8 == 0) goto L_0x0050;
    L_0x004a:
        r3 = r7.getBounds();
        r3 = r3.top;
    L_0x0050:
        if (r6 < r3) goto L_0x00a5;
    L_0x0052:
        if (r0 != 0) goto L_0x00a5;
    L_0x0054:
        r9.Z();
        r3 = r5;
        goto L_0x000f;
    L_0x0059:
        if (r0 != r1) goto L_0x006e;
    L_0x005b:
        r0 = r2;
    L_0x005c:
        if (r0 == 0) goto L_0x0064;
    L_0x005e:
        r1 = r0.exists();
        if (r1 != 0) goto L_0x009e;
    L_0x0064:
        r0 = new com.sutuijingling.result.c;
        r1 = 404; // 0x194 float:5.66E-43 double:1.996E-321;
        r2 = "找不到淘抢购宝贝!";
        r0.<init>(r1, r2);
        throw r0;
    L_0x006e:
        r3 = r9.findScroll();
        r3 = r3.exists();
        if (r3 != 0) goto L_0x007a;
    L_0x0078:
        r0 = r2;
        goto L_0x005c;
    L_0x007a:
        r9.Z();
        r3 = new java.lang.StringBuilder;
        r3.<init>();
        r6 = "current loop index: ";
        r3 = r3.append(r6);
        r3 = r3.append(r5);
        r6 = "----";
        r3 = r3.append(r6);
        r3 = r3.toString();
        r6 = new java.lang.Object[r4];
        com.sutuijingling.utils.b.b(r3, r6);
        r3 = r5;
        goto L_0x000f;
    L_0x009e:
        com.sutuijingling.utils.c.d();
        com.sutuijingling.utils.c.d(r0);
        return;
    L_0x00a5:
        r0 = r2;
        goto L_0x005c;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.sutuijingling.a.j.Y():void");
    }

    private void Z() throws UiObjectNotFoundException, c {
        if (this.w == null) {
            this.w = findByResId("com.taobao.taobao:id/pager", 1);
        }
        if (this.w == null || !this.w.exists()) {
            throw new c(HttpStatus.SC_SERVICE_UNAVAILABLE, "滚动时，找不到宝贝区域!");
        }
        simpleDragScrollWithRect(this.w.getBounds(), true);
    }

    private UiObject aa() throws UiObjectNotFoundException {
        UiObject findByResId = findByResId("com.taobao.taobao:id/rl_radio_root2", 1);
        if (!findByResId.exists()) {
            findByResId = findByResId("com.taobao.taobao:id/radio_tab2", 1);
            if (!findByResId.exists()) {
                findByResId = findText("爆款返场", 1);
                if (findByResId.exists()) {
                }
            }
        }
        return findByResId;
    }

    private UiObject ab() throws UiObjectNotFoundException, c {
        String title1 = this.searchParams.getTitle1();
        b.b("go find taoqianggou item: " + title1, new Object[0]);
        UiSelector resourceId = new UiSelector().resourceId("android:id/title");
        for (int i = 0; i < 10; i++) {
            UiObject uiObject = new UiObject(resourceId.instance(i));
            if (uiObject == null || !uiObject.exists()) {
                break;
            }
            String text = uiObject.getText();
            if (org.apache.commons.lang.c.a(text)) {
                b.b(" curr title not text....", new Object[0]);
            } else {
                if (text.contains("..")) {
                    text = text.replaceAll(".", "");
                }
                text = text.trim();
                b.b("the item title: " + text, new Object[0]);
                if (title1.startsWith(text)) {
                    b.b("hit the item------", new Object[0]);
                    UiObject fromParent = uiObject.getFromParent(new UiSelector().className("android.widget.FrameLayout"));
                    if (fromParent == null || !fromParent.exists()) {
                        b.b(" cannot find the frame obj....", new Object[0]);
                    } else {
                        fromParent = fromParent.getChild(new UiSelector().resourceId("com.taobao.taobao:id/tv_reminder_area").text("提醒我"));
                        if (fromParent != null && fromParent.exists()) {
                            return fromParent;
                        }
                        b.b(" cannot find the btn obj....", new Object[0]);
                    }
                } else {
                    continue;
                }
            }
        }
        return null;
    }

    private boolean ac() throws UiObjectNotFoundException, c {
        UiObject af = af();
        if (af == null || !af.exists()) {
            throw new c(HttpStatus.SC_SERVICE_UNAVAILABLE, "滚动找宝贝时，没有在淘抢购页面中找到对应的开抢时间按钮!");
        }
        int displayWidth = this.device.getDisplayWidth() / 2;
        return af.getBounds().left < displayWidth && af.getBounds().right > displayWidth;
    }

    private void ad() throws UiObjectNotFoundException, c {
        UiObject ae = ae();
        com.sutuijingling.utils.c.c();
        if (ae == null || !ae.exists()) {
            throw new c(HttpStatus.SC_SERVICE_UNAVAILABLE, "没有在淘抢购页面中找到对应的开抢时间按钮!");
        }
        com.sutuijingling.utils.c.d(ae);
        com.sutuijingling.utils.c.d();
    }

    private UiObject ae() throws UiObjectNotFoundException, c {
        int i = 0;
        while (true) {
            int i2 = i + 1;
            if (i >= 15) {
                break;
            }
            UiObject af = af();
            if (af == null || !af.exists()) {
                String str = "com.taobao.taobao:id/tv_batch_time";
                af = findByResIdWithInstance("com.taobao.taobao:id/tv_batch_time", 1, 4);
                if (af == null || !af.exists()) {
                    break;
                }
                com.sutuijingling.utils.c.d();
                com.sutuijingling.utils.c.d(af);
                i = i2;
            } else {
                return af;
            }
        }
        throw new c(HttpStatus.SC_SERVICE_UNAVAILABLE, "没有在淘抢购页面中找到对应的开抢时间按钮!");
    }

    private UiObject af() throws UiObjectNotFoundException, c {
        String str = "com.taobao.taobao:id/tv_batch_time";
        UiObject findByResIdAndText = findByResIdAndText("com.taobao.taobao:id/tv_batch_time", 1, this.searchParams.getKeyword());
        if (findByResIdAndText == null || !findByResIdAndText.exists()) {
            return findByResIdAndText;
        }
        UiObject fromParent = findByResIdAndText.getFromParent(new UiSelector().resourceId("com.taobao.taobao:id/tv_batch_state").text("已开场"));
        if (fromParent != null && fromParent.exists()) {
            return null;
        }
        fromParent = findByResIdAndText.getFromParent(new UiSelector().resourceId("com.taobao.taobao:id/tv_batch_state").text("抢购进行中"));
        return (fromParent == null || !fromParent.exists()) ? findByResIdAndText : null;
    }

    private void ag() {
        a.c();
    }

    private boolean ah() {
        return findByResId("com.taobao.taobao:id/tv_batch_time", 1).exists() || findByResId("com.taobao.taobao:id/radio_tab0", 1).exists();
    }

    private void ai() throws UiObjectNotFoundException, c {
        if (isPackageTaobao()) {
            ag();
            com.sutuijingling.utils.c.e();
            checkTaoqianggouTipDialog();
        } else {
            ag();
            com.sutuijingling.utils.c.e();
            checkTaoqianggouTipDialog();
        }
        if (!ah()) {
            com.sutuijingling.utils.c.c();
            checkLocationMock();
            if (!ah()) {
                com.sutuijingling.utils.c.c();
                checkNetworkTip();
                if (!ah()) {
                    com.sutuijingling.utils.c.c();
                    checkNetflowTip();
                    if (!ah()) {
                        com.sutuijingling.utils.c.e();
                        checkNetflowTip();
                        if (!ah()) {
                            checkNewVersionTip();
                            if (!ah()) {
                                checkFirstOpenMainTaobao();
                                com.sutuijingling.utils.c.e();
                                if (!ah()) {
                                    checkWebviewLayout();
                                    com.sutuijingling.utils.c.e();
                                    if (!ah()) {
                                        checkNewVersionTip();
                                        com.sutuijingling.utils.c.e();
                                        if (!ah()) {
                                            checkTaoqianggouTipDialog();
                                            if (!ah()) {
                                                throw new c(HttpStatus.SC_SERVICE_UNAVAILABLE, "没有成功打开淘抢购页面!");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    public void V() throws UiObjectNotFoundException, c {
        g(0);
        if (this.searchParams.isTaoqianggou()) {
            boolean isTKLItem = this.searchParams.isTKLItem();
            String tklItemUrl = this.searchParams.getTklItemUrl();
            if (isTKLItem) {
                backToHome(this.device);
                a.e(tklItemUrl);
                doOpenTBAndDirectToItem();
                W();
            } else {
                ai();
                ad();
                Y();
            }
            this.device.pressBack();
            com.sutuijingling.utils.c.b();
            this.device.pressBack();
            w.a(this.missionId, (int) WorkStatus.NetflowOver);
        }
    }
}
